package Interface.Hoteleria;

import Interface.Acceso;
import Interface.GUIM;
import Interface.Vista_Visitante;
import LN.Alquileres.Pileta;
import LN.Alquileres.Registro_Pileta;
import LN.Persona.Usuario.Administrador;
import LN.Persona.Usuario.Operador;
import LN.Persona.Visitante.Afiliado;
import LN.Persona.Visitante.Visitante;
import LN.Varios.Caja;
import LN.Varios.Hosteria;
import LN.Varios.Lote;
import java.util.Calendar;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;

public class Vista_Pileta extends javax.swing.JPanel {

    private Lote unLote;
    private Caja unCaja;
    private Hosteria unaHosteria;
    private static Visitante unAfiliado;
    private Pileta unaPileta;

    public Vista_Pileta(Hosteria unaHosteria) {
        this.unaHosteria = unaHosteria;
        unaPileta = unaHosteria.getPileta();
        initComponents();
        iniciarInterface();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jTextField1 = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        txt_Afiliado = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        spinner_afiliados = new javax.swing.JSpinner();
        spinner_personas = new javax.swing.JSpinner();
        buttonCircle2 = new org.edisoncor.gui.button.ButtonCircle();
        jLabel4 = new javax.swing.JLabel();
        txt_total_a_pagar = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txt_excedentes = new javax.swing.JTextField();
        panelRect1 = new org.edisoncor.gui.panel.PanelRect();
        btn_abrirLote = new javax.swing.JButton();
        btn_modificar_parametros = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        txt_precio_invitado = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        txt_total_bañeros = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbl_registros_pileta = new javax.swing.JTable();

        setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.LINE_AXIS));

        jTextField1.setEditable(false);
        jTextField1.setBackground(new java.awt.Color(153, 153, 153));
        jTextField1.setFont(new java.awt.Font("Copperplate Gothic Light", 1, 18)); // NOI18N
        jTextField1.setForeground(new java.awt.Color(255, 255, 255));
        jTextField1.setText("Pileta de Natación");
        jTextField1.setFocusable(false);
        jTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1ActionPerformed(evt);
            }
        });

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Detalles del Registro"));

        jLabel1.setFont(new java.awt.Font("Bell MT", 1, 14)); // NOI18N
        jLabel1.setText("Afiliado Encargado:");

        jLabel2.setFont(new java.awt.Font("Bell MT", 1, 14)); // NOI18N
        jLabel2.setText("Cantidad Total de Afiliados:");

        jLabel3.setFont(new java.awt.Font("Bell MT", 1, 14)); // NOI18N
        jLabel3.setText("Cantidad Total de Personas:");

        spinner_afiliados.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                spinner_afiliadosStateChanged(evt);
            }
        });

        spinner_personas.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                spinner_personasStateChanged(evt);
            }
        });

        buttonCircle2.setText("buttonCircle1");
        buttonCircle2.setToolTipText("Buscar un Afiliado");
        buttonCircle2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonCircle2ActionPerformed(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Bell MT", 1, 14)); // NOI18N
        jLabel4.setText("Cantidad de Invitados Execentes");

        jLabel5.setFont(new java.awt.Font("Bell MT", 1, 14)); // NOI18N
        jLabel5.setText("Monto Total a Pagar:");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(spinner_afiliados, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(txt_excedentes, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(spinner_personas))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txt_total_a_pagar, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE))))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txt_Afiliado)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(buttonCircle2, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txt_Afiliado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addComponent(buttonCircle2, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(spinner_afiliados, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(spinner_personas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txt_excedentes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(txt_total_a_pagar, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        panelRect1.setBackground(new java.awt.Color(255, 255, 255));
        panelRect1.setForeground(new java.awt.Color(255, 255, 255));
        panelRect1.setColorPrimario(new java.awt.Color(255, 255, 255));
        panelRect1.setColorSecundario(new java.awt.Color(102, 102, 102));
        panelRect1.setPreferredSize(new java.awt.Dimension(150, 184));

        btn_abrirLote.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/Guardar_2.png"))); // NOI18N
        btn_abrirLote.setText("Registrar");
        btn_abrirLote.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_abrirLoteActionPerformed(evt);
            }
        });

        btn_modificar_parametros.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/postits.png"))); // NOI18N
        btn_modificar_parametros.setText("<html><p>Modificar</p><p>Parámetros</p></html>");
        btn_modificar_parametros.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_modificar_parametrosActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelRect1Layout = new javax.swing.GroupLayout(panelRect1);
        panelRect1.setLayout(panelRect1Layout);
        panelRect1Layout.setHorizontalGroup(
            panelRect1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelRect1Layout.createSequentialGroup()
                .addGap(15, 15, 15)
                .addGroup(panelRect1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(btn_modificar_parametros, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btn_abrirLote, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(15, Short.MAX_VALUE))
        );
        panelRect1Layout.setVerticalGroup(
            panelRect1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelRect1Layout.createSequentialGroup()
                .addGap(14, 14, 14)
                .addComponent(btn_abrirLote)
                .addGap(18, 18, 18)
                .addComponent(btn_modificar_parametros, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Información de Estado"));

        jLabel6.setFont(new java.awt.Font("Bell MT", 1, 14)); // NOI18N
        jLabel6.setText("Costo por invitado excedente:");

        jLabel7.setFont(new java.awt.Font("Bell MT", 1, 14)); // NOI18N
        jLabel7.setText("Total de bañeros registrados:");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txt_precio_invitado, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(txt_total_bañeros, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txt_precio_invitado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(jLabel7)
                    .addComponent(txt_total_bañeros, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        tbl_registros_pileta.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Encargado de Grupo", "Cantidad de Personas", "Monto Adjudicado", "Fecha y Hora"
            }
        ));
        jScrollPane1.setViewportView(tbl_registros_pileta);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTextField1)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(panelRect1, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(panelRect1, javax.swing.GroupLayout.DEFAULT_SIZE, 156, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        add(jPanel1);
    }// </editor-fold>//GEN-END:initComponents

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
    }//GEN-LAST:event_jTextField1ActionPerformed

    private void buttonCircle2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCircle2ActionPerformed
        JDialog frame;
        if (SwingUtilities.getWindowAncestor(this) instanceof JDialog) {
            frame = new JDialog((JDialog) SwingUtilities.getWindowAncestor(this), true);
        } else {
            frame = new JDialog((JFrame) SwingUtilities.getWindowAncestor(this), true);
        }
        Vista_Visitante panel_captura_visitante = new Vista_Visitante(unaHosteria, unAfiliado);
        frame.getContentPane().removeAll();
        frame.getContentPane().add(panel_captura_visitante);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.show();

        if (panel_captura_visitante.getSelected_Visitante().getSelectedRowCount() != 0) {
            Visitante unVisitante = (Visitante) panel_captura_visitante.getSelected_Visitante().getValueAt(panel_captura_visitante.getSelected_Visitante().getSelectedRow(), 0);
            unAfiliado = unVisitante;
            if (unAfiliado != null) {
                txt_Afiliado.setText(unAfiliado.getApellido() + " " + unAfiliado.getNombre());
            }
        }
    }//GEN-LAST:event_buttonCircle2ActionPerformed

    private void btn_abrirLoteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_abrirLoteActionPerformed
        int cantidad_afiliado = (int) spinner_afiliados.getValue();
        int cantidad_personas = (int) spinner_personas.getValue();
        double monto_entradas = Double.valueOf(txt_total_a_pagar.getText());
        Date fecha_registro = new Date();
        if (unAfiliado instanceof Afiliado) {
            try {
                unaPileta.registrar_Entrada((Afiliado) unAfiliado, cantidad_afiliado, cantidad_personas, monto_entradas, fecha_registro);
                unLote = ultimoLote();
                if (monto_entradas != 0.0) {
                    unLote.altaMovimiento(fecha_registro, GUIM.getHoraActual(), monto_entradas, "Ingreso", null);
                }
                GUIM.cargarTablaRegistros(tbl_registros_pileta, unaPileta.getRegistros());
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(this, ex.getMessage());
            }
        } else {
            JOptionPane.showMessageDialog(jPanel1, "El representante de grupo debe ser un Afiliado");
        }



    }//GEN-LAST:event_btn_abrirLoteActionPerformed

    private void btn_modificar_parametrosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_modificar_parametrosActionPerformed
        JDialog frame;
        if (SwingUtilities.getWindowAncestor(this) instanceof JDialog) {
            frame = new JDialog((JDialog) SwingUtilities.getWindowAncestor(this), true);
        } else {
            frame = new JDialog((JFrame) SwingUtilities.getWindowAncestor(this), true);
        }
        Parametros_Pileta parametros = new Parametros_Pileta(unaHosteria.getPileta());
        frame.getContentPane().removeAll();
        frame.getContentPane().add(parametros);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.show();

    }//GEN-LAST:event_btn_modificar_parametrosActionPerformed

    private void spinner_afiliadosStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinner_afiliadosStateChanged
        if ((int) spinner_afiliados.getValue() < 0) {
            JOptionPane.showMessageDialog(this, "No se pueden ingresar valores negativos");
            spinner_afiliados.setValue(0);
        }
        spinner_personas.setValue(spinner_afiliados.getValue());

    }//GEN-LAST:event_spinner_afiliadosStateChanged

    private void spinner_personasStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinner_personasStateChanged
        if ((int) spinner_personas.getValue() < (int) spinner_afiliados.getValue()) {
            JOptionPane.showMessageDialog(this, "En número total de personas debe ser mayor o igual a la cantidad de Afiliados");
            spinner_personas.setValue(spinner_afiliados.getValue());
        }

        if ((int) spinner_personas.getValue() > ((int) spinner_afiliados.getValue()) * 2) {
            int aceptado = (int) spinner_afiliados.getValue() * 2;
            int excedentes = (int) spinner_personas.getValue() - aceptado;
            txt_excedentes.setText(String.valueOf(excedentes));
            txt_total_a_pagar.setText(String.valueOf(excedentes * unaPileta.getPrecio_invitado()));
        } else {
            txt_excedentes.setText("0");
            txt_total_a_pagar.setText("0.0");
        }
    }//GEN-LAST:event_spinner_personasStateChanged
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_abrirLote;
    private javax.swing.JButton btn_modificar_parametros;
    private org.edisoncor.gui.button.ButtonCircle buttonCircle2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTextField1;
    private org.edisoncor.gui.panel.PanelRect panelRect1;
    private javax.swing.JSpinner spinner_afiliados;
    private javax.swing.JSpinner spinner_personas;
    private javax.swing.JTable tbl_registros_pileta;
    private javax.swing.JTextField txt_Afiliado;
    private javax.swing.JTextField txt_excedentes;
    private javax.swing.JTextField txt_precio_invitado;
    private javax.swing.JTextField txt_total_a_pagar;
    private javax.swing.JTextField txt_total_bañeros;
    // End of variables declaration//GEN-END:variables

    private void iniciarInterface() {
        unCaja = unaHosteria.getCajaPrincipal();

        if (Acceso.getLogueado() != null) {
            if (Acceso.getLogueado() instanceof Operador) {
                btn_modificar_parametros.setEnabled(false);
            } else if (Acceso.getLogueado() instanceof Administrador) {
                btn_modificar_parametros.setEnabled(true);
            }
        }

        txt_precio_invitado.setEditable(false);
        txt_precio_invitado.setFocusable(false);
        txt_precio_invitado.setText(String.valueOf(unaPileta.getPrecio_invitado()));


        Calendar mañana = Calendar.getInstance();
        mañana.add(Calendar.DAY_OF_MONTH, +1);
        Calendar ayer = Calendar.getInstance();
        ayer.add(Calendar.DAY_OF_MONTH, -1);

        List<Registro_Pileta> unFiltro = new LinkedList<>();
        Date hoy = new Date();
        for (Registro_Pileta unRegistro : unaPileta.getRegistros()) {

            if (unRegistro.getFecha_entrada().after(ayer.getTime()) && unRegistro.getFecha_entrada().before(mañana.getTime())) {
                unFiltro.add(unRegistro);


            }

        }
        GUIM.cargarTablaRegistros(tbl_registros_pileta, unFiltro);
        txt_total_bañeros.setText(String.valueOf(unFiltro.size()));

    }

    public void verificarCierrePendiente() {
        boolean hayInicio = false;
        int res = 0;
        Lote oneLote = ultimoLote();
        if (oneLote != null) {
            if (oneLote.isCerrado() != true && "".equals(oneLote.getHoraCierre())) {
                if (oneLote.getMovimientos() != null) {
                    res = JOptionPane.showConfirmDialog(this, "Aún no se ha realizado el cierre de caja de las ultimas actividades, ¿desea cerrarlo?",
                            "Advertencia", JOptionPane.YES_NO_OPTION);
                }
                if (res == JOptionPane.YES_OPTION) {
                }
            }
        }
    }

    public Lote ultimoLote() {
        boolean estaCerrado = false;
        Lote ultimo_Lote_Cerrado = null;
        List<Lote> lotesAnteriores = unCaja.getLotes();


        if (!lotesAnteriores.isEmpty()) {
            ultimo_Lote_Cerrado = lotesAnteriores.get(lotesAnteriores.size() - 1);
        }
        return ultimo_Lote_Cerrado;
    }

    private void lote_del_Dia() {
        Date hoy = new Date();
//        Calendar mañana = Calendar.getInstance();
//        mañana.add(Calendar.DAY_OF_MONTH, 1);
        Calendar ayer = Calendar.getInstance();
        ayer.add(Calendar.DAY_OF_MONTH, -2);
        for (Lote l : unCaja.getLotes()) {
            if ((l.getFechaLote().after(ayer.getTime())) && (l.getFechaLote().before(hoy))) {
                this.unLote = l;
            }
        }
    }

    private Lote lote_de_ayer() {
        Calendar ayer = Calendar.getInstance();
        ayer.add(Calendar.DAY_OF_MONTH, -1);

        Calendar anteayer = Calendar.getInstance();
        anteayer.add(Calendar.DAY_OF_MONTH, -2);
        for (Lote l : unCaja.getLotes()) {
            if ((l.getFechaLote().after(anteayer.getTime())) && (l.getFechaLote().before(ayer.getTime()))) {
                this.unLote = l;
            }
        }
        return unLote;
    }
}
